package dao;

import java.util.LinkedList;
import java.util.List;

import entities.Artist;


public class ArtistDAO 
{

	private static final ArtistDAO instance = new ArtistDAO();
	private List<Artist> artists;
	
	private ArtistDAO(){
		artists = new LinkedList<Artist>();
		Artist artist = null;

		//Album artists
		
		artist = Artist.newInstance("Avril Lavinge", 1L);
		artists.add(artist);
		artist = Artist.newInstance("Rolling Stones", 2L);
		artists.add(artist);
		artist = Artist.newInstance("Mariah Carey", 3L);
		artists.add(artist);
		artist = Artist.newInstance("Marc Anthony",4L);
		artists.add(artist);
		artist = Artist.newInstance("Gary Moore",5L);
		artists.add(artist);
		artist = Artist.newInstance("Marco Antonio Solis",6L);
		artists.add(artist);
		artist = Artist.newInstance("Daddy Yankee",7L);
		artists.add(artist);
		artist = Artist.newInstance("Tego Calderon",8L);
		artists.add(artist);
		artist = Artist.newInstance("Elvis Crespo",9L);
		artists.add(artist);
		artist = Artist.newInstance("Michael Ryan",10L);
		artists.add(artist);
		artist = Artist.newInstance("Axel Rudi Pell",11L);
		artists.add(artist);
		artist = Artist.newInstance("Andras Schiff",12L);
		artists.add(artist);
		artist = Artist.newInstance("Susan Tedeschi",13L);
		artists.add(artist);
		artist = Artist.newInstance("Jennifer Hudson",14L);
		artists.add(artist);
		artist = Artist.newInstance("Lucinda Williams",15L);
		artists.add(artist);
		artist = Artist.newInstance("Various Artists",16L);
		artists.add(artist);
		artist = Artist.newInstance("Leona Lewis",16L);
		artists.add(artist);
		artist = Artist.newInstance("Harry Belafonte",17L);
		artists.add(artist);
		
		//Song artists
		artist = Artist.newInstance("Los Cantantes",500L);
		artists.add(artist);
		artist = Artist.newInstance("Voltio",501L);
		artists.add(artist);
		
		//Video artists
		artist = Artist.newInstance("The actor 1",1000L);
		artists.add(artist);
		artist = Artist.newInstance("The actor 2",1001L);
		artists.add(artist);
		artist = Artist.newInstance("The actor 3",1002L);
		artists.add(artist);
	}
	
	public static ArtistDAO getInstance() {
		return instance;
	}

	public synchronized Artist findArtist(Long a_id) {
		Artist result = null;
		for (Artist s : artists){
			if (s.getA_id().equals(a_id)){
				result = s;
			}
		}
		return result;
	}

	public synchronized void addArtist(Artist obj) throws RecordDuplicateException{
		if (findArtist(obj.getA_id()) != null){
			throw new RecordDuplicateException("Customer with id: " + obj.getA_id() + " is already in the db.");
		}
		else {
			artists.add(obj);
		}
	}
}
